package com.intexh.speedandroid.net;

import android.app.Application;

import com.intexh.speedandroid.BuildConfig;
import com.intexh.speedandroid.net.interfaces.OnRequestCallBack;
import com.intexh.speedandroid.net.interfaces.OnUpLoadCallBack;
import com.intexh.speedandroid.net.request.RequestModel1;
import com.intexh.speedandroid.net.request.RequestModel2;
import com.intexh.speedandroid.net.request.RequestModel3;
import com.intexh.speedandroid.net.request.RequestModel4;
import com.lzy.okgo.OkGo;

import java.io.File;
import java.util.Map;


/**
 * Created by intexh on 2016/6/4.
 */
public enum NetworkManager{
    INSTANCE;
    public void init(Application application) {
        //必须调用初始化
        OkGo.getInstance().init(application);
//        OkHttpClient.Builder builder = new OkHttpClient.Builder();
//        //全局的读取超时时间
//        builder.readTimeout(15000, TimeUnit.MILLISECONDS);
//        //全局的写入超时时间
//        builder.writeTimeout(15000, TimeUnit.MILLISECONDS);
//        //全局的连接超时时间
//        builder.connectTimeout(15000, TimeUnit.MILLISECONDS);
    }

    //请求 post
    public void post(String api, Map<String, String> params, OnRequestCallBack callBack) {
        switch (BuildConfig.SERVER_MODE){   //在gradle 配置请求类型
            case 1:
                RequestModel1.INSTANCE.post("",api,params,callBack);
                break;
            case 2:
                RequestModel2.INSTANCE.post("",api,params,callBack);
                break;
            case 3:
                RequestModel3.INSTANCE.post("",api,params,callBack);
                break;
            case 4:
                RequestModel4.INSTANCE.post("",api,params,callBack);
                break;
        }
    }

    //请求 get
    public void get(String api, Map<String, String> params, OnRequestCallBack callBack) {
        switch (BuildConfig.SERVER_MODE){
            case 1:
                RequestModel1.INSTANCE.get("",api,params,callBack);
                break;
            case 2:
                RequestModel2.INSTANCE.get("",api,params,callBack);
                break;
            case 3:
                RequestModel3.INSTANCE.get("",api,params,callBack);
                break;
            case 4:
                RequestModel4.INSTANCE.get("",api,params,callBack);
                break;
        }
    }

    //请求文件上传
    public void upLoadFile(String api, String key, File file, OnUpLoadCallBack callBack) {
        switch (BuildConfig.SERVER_MODE){
            case 1:
                RequestModel1.INSTANCE.upLoadFile(api,key,file,callBack);
                break;
            case 2:
                RequestModel2.INSTANCE.upLoadFile(api,key,file,callBack);
                break;
            case 3:
                RequestModel3.INSTANCE.upLoadFile(api,key,file,callBack);
                break;
            case 4:
                RequestModel4.INSTANCE.upLoadFile(api,key,file,callBack);
                break;
        }
    }


}
